Use the filename (when available) to disambiguate between routes and waypoints
authorrobertl <robertl>
Sun, 22 Oct 2006 22:13:29 +0000 (22:13 +0000)
committerrobertl <robertl>
Sun, 22 Oct 2006 22:13:29 +0000 (22:13 +0000)
in Magellan file mode.

magproto.c

index e04fd1dc188b6a0b1f6d7f3b9be35591ac6394db..907d79b63eeb4b00aa31a39d63bd814a46aeab4b 100644 (file)
@@ -50,6 +50,8 @@ static int route_out_count;
 static int waypoint_read_count;
 static int wpt_len = 8;
 static const char *curfname;
+static int extension_hint;
+
 /*
  * Magellan's firmware is *horribly* slow to send the next packet after
  * we turn around an ack while we are reading from the device.  It's
@@ -458,16 +460,24 @@ retry:
                        waypt_status_disp(waypoint_read_count, 
                                        waypoint_read_count);
                }
-               switch (objective)
-               {
-                       case wptdata:
+
+               if (extension_hint) {
+                       if (extension_hint == WPTDATAMASK) {
                                waypt_add(wpt);
-                               break;
-                       case rtedata:
-                               ENQUEUE_TAIL(&rte_wpt_tmp, &wpt->Q);
-                               break;
-                       default:
-                               break;
+                       } else if (extension_hint == RTEDATAMASK) {
+                                       ENQUEUE_TAIL(&rte_wpt_tmp, &wpt->Q);
+                       }
+               } else {
+                       switch (objective) {
+                               case wptdata:
+                                       waypt_add(wpt);
+                                       break;
+                               case rtedata:
+                                       ENQUEUE_TAIL(&rte_wpt_tmp, &wpt->Q);
+                                       break;
+                               default:
+                                       break;
+                       }
                }
        }
        if (strncmp(ibuf, "$PMGNTRK,", 7) == 0) {
@@ -711,6 +721,7 @@ static void
 mag_rd_init_common(const char *portname)
 {
        waypoint_read_count = 0;
+       char *ext;
 
        if (bs) {
                bitrate=atoi(bs);
@@ -736,6 +747,24 @@ mag_rd_init_common(const char *portname)
                curfname = portname;
        }
 
+       /*
+        * I'd rather not derive behaviour from filenames but since
+        * we can't otherwise tell if we should put a WPT on the route
+        * queue or the WPT queue in the presence of (-w -r -t) we 
+        * divine a hint from the filename extension when we can.
+        */
+       ext = strrchr(curfname, '.');
+       if (ext) {
+               ext++;
+               if (0 == case_ignore_strcmp(ext, "upt")) {
+                       extension_hint = WPTDATAMASK;
+               } else if (0 == case_ignore_strcmp(ext, "log")) {
+                       extension_hint = TRKDATAMASK;
+               } else if (0 == case_ignore_strcmp(ext, "rte")) {
+                       extension_hint = RTEDATAMASK;
+               } 
+       }
+
        return;
 }